<template>
    <el-card shadow="never" style="border: 0;">
        <template #header v-if="action=='edit'">
            <el-alert
                    type="warning"
                    show-icon>
                非调试模式下，提交后请清空缓存才能生效！
            </el-alert>
        </template>
        <yun-form
                v-if="columns"
                :data="data"
                ref="yunform"
                :columns="columns">
            <template #default>
                {:token_field()}
            </template>
            <template #groupids="{rows}" required>
                <el-form-item label="{:__('所属组别')}:" prop="groupids">
                    <el-tree-select
                            v-model="rows.groupids"
                            :data="groupdata"
                            multiple
                            check-strictly
                            :default-expand-all="true"
                            :props='{label:"name",children:"childlist",value:"id"}'
                    >
                    </el-tree-select>
                </el-form-item>
            </template>
            <template #third_id="{rows}">
                <el-form-item label="绑定微信:">
                    <third :value="rows.third_id" :selectable="true" @change="changValue"></third>
                </el-form-item>
            </template>
            <template #depart_id="{rows}">
                <el-form-item label="{:__('所属部门')}:" required>
                    <el-tree-select
                            v-model="rows.depart_id"
                            :data="departdata"
                            check-strictly
                            :default-expand-all="true"
                            :props='{label:"name",children:"childlist",value:"id"}'
                    >
                    </el-tree-select>
                </el-form-item>
            </template>
        </yun-form>
    </el-card>
</template>
<script>
    import form from "@components/Form.js";
    import third from "@components/Third.js";
    import {TreeIdtoString} from "@util.js";
    export default{
        components:{'YunForm':form,'Third':third},
        data:{
            action:Yunqi.config.action,
            data:Yunqi.data.row || {},
            groupdata:TreeIdtoString(Yunqi.data.groupdata),
            departdata:TreeIdtoString(Yunqi.data.departdata),
            disabled:false,
            columns:''
        },
        onLoad:function (query){
            let ids=query.ids;
            this.columns=[
                {field: 'id',title: __('ID'),edit:'hidden'},
                {field: 'username', title: __('用户名'),edit:(ids==1)?'readonly':'text',rules:'required'},
                {field: 'password', title: __('密码'),edit:'password',rules:(Yunqi.config.action=='add')?'required':''},
                {field: 'nickname', title: __('昵称'),edit:'text',rules:'required'},
                {field: 'mobile', title: __('手机号'),edit:'text',rules:'required;mobile'},
                {
                    field: 'groupids',
                    title: __('所属组别'),
                    edit:{form:'slot',value:[]},
                    rules:'required'
                },
                {
                    field: 'depart_id',
                    title: __('所属部门'),
                    edit:{form:'slot',value:[]},
                    rules:'required'
                },
                {field: 'third_id', title: __('绑定微信'),edit:Yunqi.data.thirdLogin?'slot':false},
                {field: 'status', title: __('状态'),searchList: {'normal': __('正常'),'hidden': __('隐藏')},edit:{form:'radio',value:'normal'}}
            ];
            if(ids==1){
                this.disabled=true;
            }
        },
        methods: {
            changValue:function (e){
                this.$refs.yunform.setValue('third_id',e);
            }
        }
    }
</script>
<style>

</style>
